#include "net.h"

//创建链表
sqlink* sq_create()
{
	//创建链表指针
	sqlink* sq;
	//申请空间
	sq = (sqlink* )malloc(sizeof(sqlink));
	if( sq == NULL)
	{
		perror("malloc");
		return NULL;
	}
	//初始化值
	sq->next = NULL;

	//地址申请成功返回链表起始地址
	return sq;	
}


//尾部插入
int sq_inset(sqlink* sq, int value)
{
	sqlink* q;
	sqlink* h;
	//入口检查
	if(sq == NULL)
	{
		perror("sq null");
		return -1;
	}

	//封装一个节点
	q = (sqlink*) malloc(sizeof(sqlink));
	if(q == NULL)
	{
		perror("q NULL");
		return -1;
	}
	//赋值
	q->data = value;
	q->next = NULL;

	//寻找插入的位置
	h = sq;
	while(h->next != NULL)
	{
		h = h->next;
	}
	//update
	h->next = q;
	return 0;
}

//打印出来
void print(sqlink* sq)
{

	sqlink* h;
	h = sq;
	while(sq->next != NULL)
	{
		printf("%d\n ", h->data);
		h = h->next;
		
	}

}




















